﻿using Microsoft.AspNetCore.Mvc;
using WCS.Infrastructure.Dto.Request.Log;
using WCS.Infrastructure.Dto.Request.Organization;
using WCS.Service.Instance;
using WCS.Service.Interface;

namespace WCS.Api.Admin.Controllers
{
    /// <summary>
    /// 日志模块
    /// </summary>
    public class LogController : BaseController
    {
        private readonly IConfiguration _configuration;
        private readonly ILogService _logService;
        public LogController(IConfiguration configuration, ILogService logService, IUserService userService) : base(userService)
        {
            _configuration = configuration;
            _logService = logService;
        }

        /// <summary>
        /// 获取行为日志
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetActionLogs(DateTime startTime, DateTime endTime,int page = 1, int limit = 10, string? key = "")
        {
            var result = await _logService.GetActionLogsAsync(new LogRequestDto
            {
                Page = page,
                Limit = limit,
                Key = key,
                StartTime = startTime,
                EndTime = endTime
            });
            return Ok(result);
        }


        /// <summary>
        /// 获取错误日志
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetErrorLogs(DateTime startTime, DateTime endTime, int page = 1, int limit = 10, string? key = "")
        {
            var result = await _logService.GetErrorLogsAsync(new LogRequestDto
            {
                Page = page,
                Limit = limit,
                Key = key,
                StartTime = startTime,
                EndTime = endTime
            });
            return Ok(result);
        }

        /// <summary>
        /// 获取登录日志
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetLoginLogs(DateTime startTime, DateTime endTime, int page = 1, int limit = 10, string? key = "")
        {
            var result = await _logService.GetLoginLogsAsync(new LogRequestDto
            {
                Page = page,
                Limit = limit,
                Key = key,
                StartTime = startTime,
                EndTime = endTime
            });
            return Ok(result);
        }
    }


}
